/*
运行使用：RUST_BACKTRACE=1 cargo run
   Compiling mychk v0.1.0 (/home/lxin/workdir/tmp/pccx/rlpc/rldir/rlv01/rlv01.014.01.panic)
    Finished dev [unoptimized + debuginfo] target(s) in 0.25s
     Running `target/debug/mychk`
thread 'main' panicked at src/main.rs:8:10:
index out of bounds: the len is 3 but the index is 99
stack backtrace:
   0: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
   2: core::panicking::panic_bounds_check
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:208:5
   3: <usize as core::slice::index::SliceIndex<[T]>>::index
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/slice/index.rs:255:10
   4: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/slice/index.rs:18:9
   5: <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/vec/mod.rs:2770:9
   6: mychk::main
             at ./src/main.rs:30:10 这里支出了我们程序哪里崩溃的！main.rs:30行
   7: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

当出现 panic 时，程序默认会开始 展开（unwinding），这意味着 Rust 会回溯栈并清理它遇到的每一个函数的数据，不过这个回溯并清理的过程有很多工作。
另一种选择是直接 终止（abort），这会不清理数据就退出程序。
*/
fn main() {
    // 调用系统库崩溃。
    {
        let v = vec![1, 2, 3];
        // 直接崩溃，并且不能通过返回判断是否出错。因此需要我们自己去判断长度，避免此类错误。
        v[99];// 备注这里编译不会报错！
    }
    // 自己退出
    // panic!("my crash and burn");//直接退出并清理。
}


